const crawler = require('../../libs/crawler'),
      { crawlerConf } = require('../../config/config');

crawler({

  url: crawlerConf.url.main,
  callback () {
    const $ = window.$,
          mainTitle = $('.agency-spread-wrap h4').text(),
          $item = $('.spread-course-ul li');
    
    const data = [];

    $item.each((index, item) => {
      const $el = $(item),
            $itemLk = $el.find('a');

      // $($('.spread-course-ul li')[0]).find('.spread-course-face span').text().replace(/[^0-9]/ig, '')
      // Number($($('.spread-course-ul li')[0]).find('.spread-course-price').text().slice(1))
      // "5000.00   600.00".replace(/\s[0-9|.|\s]+/, '');

      const dataItem = {
        cid: parseInt($el.attr('report-tdw').match(/\&(.+?)\&/)[1].split('=')[1]),
        href: $itemLk.prop('href'),
        mainTitle,
        title: $el.find('h3').text(),
        posterUrl: $itemLk.find('.spread-course-cover').prop('src').replace('webp', ''),  //课程图片
        description: $el.find('.spread-course-des').text(),
        teacherImgUrl: $el.find('.spread-course-face img').prop('src').replace('webp', ''),
        teacherName: $el.find('.spread-course-face span').eq(0).text(),
        studentCount: parseInt($el.find('.spread-course-face span').eq(1).text().replace(/[^0-9]/ig, '')),
        price: Number($el.find('.spread-course-price').text().slice(1).replace(/\s[0-9|.|\s]+/, '')),
        posterKey: '',
        teacherImgKey: ''
      };

      data.push(dataItem);
    }); 
    return data;
  }

})